<template>
    <el-card class="new-course-card">
      <template #header>
        <div class="card-header">
          <span><img width="32" height="32" src="/images/edu/new-course.png">新上好课</span>
        </div>
      </template>
  
      <el-row :gutter="20">
        <el-col 
          v-for="(course, index) in newCourses" 
          :key="index" 
          :xs="24" 
          :sm="12" 
          :md="8" 
          :lg="8" 
          :xl="6"
        >
          <div class="course-item" @click="viewCourseDetail(course.id)">
            <!-- 新增封面容器 -->
          <div class="cover-wrapper">
            <el-image :src="course.cover" class="course-cover" fit="cover" />
            <!-- 早鸟优惠标签 -->
            <el-tag 
              type="warning" 
              effect="plain" 
              class="early-bird-tag"
            >
              <el-icon><AlarmClock /></el-icon>
              早鸟优惠
            </el-tag>
          </div>
            <div class="course-info">
              <h4 class="title">{{ course.name }}</h4>
              <p class="teacher">讲师：{{ course.teacher }}</p>

              <!-- 新增价格展示 -->
            <div class="price-container">
              <span class="current-price">¥{{ course.discountedPrice }}</span>
              <del class="original-price">¥{{ course.originalPrice }}</del>
              <el-tag v-if="course.discountRate" type="danger" effect="dark" size="mini" class="discount-tag">
                {{ course.discountRate }}折
              </el-tag>
            </div>
              
              <div class="meta-info">
                <div class="meta-item">
                  <el-icon><Calendar /></el-icon>
                  开课时间：{{ formatDate(course.startTime) }}
                </div>
                <div class="meta-item">
                  <el-icon><User /></el-icon>
                  报名人数：{{ course.students }}
                </div>
              </div>
  
              <div class="actions">
                <el-button 
                  type="primary" 
                  size="small" 
                  @click.stop="joinCourse(course.id)"
                >
                  立即报名
                </el-button>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </el-card>
  </template>
  
  <script setup lang="ts">
  import { Calendar, User } from '@element-plus/icons-vue'
  
  const props = defineProps({
    newCourses: {
      type: Array,
      required: true
    },
    loading: {
      type: Boolean,
      default: true
    }
  })
  
  const formatDate = (dateStr: string) => {
    return new Date(dateStr).toLocaleDateString()
  }
  
  const viewCourseDetail = (id) => {
    console.log('查看课程详情:', id)
    // 跳转到课程详情页面，新窗口打开
    window.open('/edu/details/' + id, '_blank')
  }
  
  const joinCourse = (id) => {
    // 跳转到课程详情页面，新窗口打开
    window.open('/edu/details/' + id, '_blank')
  }
  </script>
  
  <style lang="scss" scoped>
  .new-course-card {
    margin-bottom: 20px;
    border-radius: 12px;

    // 新增封面容器样式
  .cover-wrapper {
    position: relative;
    overflow: hidden;
    border-radius: 8px 8px 0 0;

    // 早鸟标签样式
    .early-bird-tag {
      position: absolute;
      top: 12px;
      right: -30px;
      padding: 8px 32px;
      transform: rotate(45deg);
      font-weight: bold;
      border-radius: 0;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
      
      // 图标样式
      .el-icon {
        vertical-align: -2px;
        margin-right: 4px;
        font-size: 14px;
      }
    }
  }

     // 新增价格样式
  .price-container {
    transition: all 0.3s ease;
    margin: 12px 0;
    display: flex;
    align-items: center;
    gap: 8px;

    &:hover {
    transform: translateX(5px);
  }

    .current-price {
      color: #f56c6c;
      font-size: 18px;
      font-weight: 700;
    }

    .original-price {
      color: #909399;
      font-size: 14px;
    }

    .discount-tag {
      align-self: flex-end;
      transform: scale(0.9);
    }
  }
  
    :deep(.el-card__header) {
      padding: 16px 24px;
      border-bottom: 1px solid #ebeef5;
    }
  
    .card-header {
      font-size: 18px;
      font-weight: 600;
      color: #303133;
      
      img {
        vertical-align: text-bottom;
        margin-right: 8px;
      }
    }
  
    .course-item {
      background: #fff;
      border-radius: 8px;
      overflow: hidden;
      transition: all 0.3s ease;
      cursor: pointer;
  
      &:hover {
        transform: translateY(-3px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
      }
  
      .course-cover {
        width: 100%;
        height: 180px;
        border-radius: 8px 8px 0 0;
      }
  
      .course-info {
        padding: 16px;
  
        .title {
          font-size: 16px;
          color: #303133;
          margin-bottom: 8px;
        }
  
        .teacher {
          font-size: 12px;
          color: #909399;
          margin-bottom: 12px;
        }
  
        .meta-info {
          margin-bottom: 12px;
  
          .meta-item {
            display: flex;
            align-items: center;
            font-size: 12px;
            color: #606266;
            margin-bottom: 8px;
  
            .el-icon {
              margin-right: 6px;
              font-size: 14px;
            }
          }
        }
  
        .actions {
          text-align: center;
          margin-top: 8px;
          .el-button {
            width: 100%;
          }
        }
      }
    }
  }
  </style>